// Copyright [2020] <unknown>
#include <bits/stdc++.h>
using namespace std;
// #define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
#define dbg(x...) { cerr << "\033[32;1m" << #x << " -> "; err(x); }
void err() { cerr << "\033[39;0m" << endl; }
template<typename T, typename... A>
void err(T a, A... x) { cerr << a << ' '; err(x...); }
#else
#define dbg(...)
#endif

#define sz(x) ((int)x.size())

const int N = 3e5+50;

typedef long long LL;


int n;
template<typename T>
struct Bit {
    inline int lowbit(int i) { return i & (-i); }

    T dat[N];

    void clear(int n) {
        memset(dat, 0, sizeof(T) * (n + 1));
    }

    inline void add(int i, T x) {
        for (; i<N; i+=lowbit(i))
            dat[i] += x;
    }

    inline T sum(int i) {
        T res = 0;
        for (; i; i-=lowbit(i))
            res += dat[i];
        return res;
    }
};

template<typename T>
struct BitRev {
    inline int lowbit(int i) { return i & (-i); }

    T dat[N];
    int nn;

    void clear(int n) {
        nn = n;
        memset(dat, 0, sizeof(T) * (n + 1));
    }

    inline void add(int i, T x) {
        i = nn - i + 1;
        for (; i<N; i+=lowbit(i))
            dat[i] += x;
    }

    inline T sum(int i) {
        T res = 0;
        i = nn - i + 1;
        for (; i; i-=lowbit(i))
            res += dat[i];
        return res;
    }
};

const int INF = 0x3f3f3f3f;

template<typename T>
struct snode {
    int id;
    T v;
    snode (int id=0, T v=INF):id(id), v(v) {}

    bool operator < (const snode &other) const {
        if (v != other.v) return v < other.v;
        else return id < other.id;
    }
};

// template<typename T>
// typedef snode T;
template<typename T>
struct segT {
    T dat[N << 2];
    LL lazy[N << 2];
    int nn;

    void init(int n) {
        nn = 1;
        while (nn < n) 
            nn <<= 1;

        for (int i=1; i<=n; ++i)
            dat[i+nn-1] = snode<int>(i, INF);
        for (int i=nn+n; i<2*nn; ++i)
            dat[i] = snode<int>(-1, INF);
        for (int i=nn-1; i>=0; --i)
            pu(i);
    }

    inline void pd(int rt) {
        if (lazy[rt]) {
            int ls = rt << 1, rs = rt << 1 | 1;
            // dat[ls].v = dat[rs].v = lazy[ls] = lazy[rs] = lazy[rt];
            dat[ls].v += lazy[rt];
            dat[rs].v += lazy[rt];
            lazy[ls] += lazy[rt];
            lazy[rs] += lazy[rt];
            lazy[rt] = 0;
        }
    }

    inline void pu(int rt) {
        dat[rt] = min(dat[rt<<1], dat[rt<<1|1]);
    }

    
    int L, R;

    void u(int l, int r, int rt, int v) {
        if (L <= l && r <= R) {
            // dat[rt].v = lazy[rt] = v;
            dat[rt].v += v;
            lazy[rt] += v;
            return;
        }
        int m = (l+r) >> 1;
        pd(rt);
        if (L <= m) u(l, m, rt<<1, v);
        if (m+1<=R) u(m+1, r, rt<<1|1, v);
        pu(rt);
    }
    T q(int l, int r, int rt) {
        // dbg(l, r, rt, dat[rt].v);
        if (L <= l && r <= R) {
            return dat[rt];
        }
        int m = (l + r) >> 1; pd(rt);
        T v1 = snode<int>(-1, INF), v2 = snode<int>(-1, INF);
        if (L <= m) v1 = q(l, m, rt<<1);
        if (m+1<=R) v2 = q(m+1, r, rt<<1|1);
        pu(rt);
        return min(v1, v2);
    }
    void u(int l, int r, int x) {
        // dbg(l, r, x);
        L = l;
        R = r;
        u(1, nn, 1, x);
    }
    T q(int l, int r) {
        L = l;
        R = r;
        return q(1, nn, 1);
    }
};

segT<snode<int>> seg;

int p[N], q[N], cp[N];

int ans[N];

int main(int argc, char const *argv[]) {
    // code
    scanf("%d", &n);
    for (int i=1; i<=n; ++i) {
        scanf("%d", &p[i]);
        cp[p[i]] = i;
    }

    for (int i=1; i<=n; ++i)
        scanf("%d", &q[i]);

    seg.init(n);
    ans[0] = n;
    int now = 0, cur = 1;
    bool update = true;
    for (int i=n; i>=1; --i) {
        // if (update) {
            seg.u(cp[i], cp[i], -INF);
            seg.u(1, cp[i], -1);   
        // }
        int old = now;
        while (seg.q(1, n).v < 0 && now < n) {
            // ans[now] = i;
            ++now;
            seg.u(1, q[now], 1);
            // dbg(now, q[now]);
            // ++now;

            // for (int i=1; i<=n; ++i)
            //     dbg(i, seg.q(i, i).v);
        }
        // dbg(old, now);
        for (int j=old; j<now; ++j)
            ans[j] = i;
        if (now == n)
            break;
    }
    for (int i=0; i<n; ++i)
        printf("%d%c", ans[i], i==n-1? '\n':' ');

    return 0;
}
